<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>划款指令</title>
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/font.css">
    <script language="javascript" src="../dayin/jquery-1.4.4.min.js"></script>
    <!--
    如果您使用的是高版本jQuery调用下面jQuery迁移辅助插件即可
    <script src="http://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js"></script>
    -->
    <script language="javascript" src="../dayin/jquery.jqprint-0.3.js"></script>
    <script language="javascript">
        //打印
        function aa(){
            $("#day").jqprint();
        }
    </script>

    <script type="text/html" id="barDemo">

        <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-normal layui-icon layui-icon-edit" lay-event="update">编辑</a>
        <a href="javascript:;"  class="layui-btn layui-btn-danger layui-btn-xs layui-icon layui-icon-delete"   lay-event="delete" >删除</a>
        <a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-xs layui-border-blue"  lay-event="dayin"><i class="layui-icon">&#xe63c;</i>打印单据</a>
    </script>
</head>
<body>
<blockquote class="layui-elem-quote news_search">
    <!--头部工具栏-->
    <div class="demoTable" id="demoTableId" hidden="true">
        <form class="layui-form">
            划款日期
            <div class="layui-input-inline">
                <input type="date" name="tranDate"  placeholder="请输入业务日期" autocomplete="off" class="layui-input"/>
            </div>
            到账日期
            <div class="layui-input-inline">
                <input type="date" name="arrival" placeholder="请输入业务日期" autocomplete="off" class="layui-input"/>
            </div>
            <button id="search" class="layui-btn  layui-btn-primary layui-bg-gray" lay-submit data-type="reload" lay-filter="provinceSearch">
                <i class="layui-icon">&#xe615;</i>
            </button>
            <div class="layui-input-inline" style="float:right;">
                <a href="javascript:;" class="layui-btn layui-btn-normal"  lay-event="add"><i class="layui-icon">&#xe654;</i>创建划款</a>
                <a href="javascript:;" class="layui-btn  layui-btn-danger "  lay-event="batchDel"><i class="layui-icon">&#xe640;</i>批量删除</a>
            </div>
        </form>
    </div>

    <table id="demo" lay-filter="test"></table>

<!--添加和修改弹出对话框-->
<div style="display: none;" id="MaxDiv">
    <div style="margin-top: 40px;margin-left: 120px;">
        <form class="layui-form" id="mainForm" method="post" lay-filter="myForm">
            <div class="layui-form-item" >
                <div class="layui-inline" style="display: none" >
                    <label class="layui-form-label">划款编号:</label>
                    <div class="layui-input-inline">
                    <input type="text" name="tranId"  id="stopText"   placeholder="请输入划款编号" autocomplete="off" class="layui-input" />
                    </div>
                </div>

                <div class="layui-inline" >
                    <label class="layui-form-label" >接受账户</label>
                    <div class="layui-input-inline">
                        <select name="caId" id="caIds" lay-verify="required">
                            <!--<option value="0">&#45;&#45;请选择&#45;&#45;</option>
                            <option value="1">农业银行</option>
                            <option value="2">商业银行</option>
                            <option value="3">邮政银行</option>
                            <option value="4">建设银行</option>-->
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">划款用途:</label>
                    <div class="layui-input-inline">
                        <input type="text" name="purpose"  placeholder="请输入划款的用途" autocomplete="off" class="layui-input" />
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline" >
                <label class="layui-form-label">划款金额:</label>
                <div class="layui-input-inline">
                    <input type="text" name="money" id="txt2"  placeholder="请输入划款金额" lay-verify="required"  autocomplete="off" class="layui-input" />
                </div>
                </div>
                <div class="layui-inline" >
                <label class="layui-form-label">划款日期:</label>
                <div class="layui-input-inline">
                    <input type="date" name="tranDate" id="txt3"  placeholder="请输入划款日期" lay-verify="required" autocomplete="off" class="layui-input" />
                </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline" >
                <label class="layui-form-label">到账日期:</label>
                <div class="layui-input-inline">
                    <input type="date" name="arrival" id="scoreDates" lay-verify="required"   placeholder="请输入到账日期"  class="layui-input" />
                </div>
                </div>
                <div class="layui-inline" >
                    <label class="layui-form-label" >划款账户</label>
                    <div class="layui-input-inline">
                        <select name="caId" id="caId" lay-verify="required">
                            <!--<option value="0">&#45;&#45;请选择&#45;&#45;</option>
                            <option value="1">农业银行</option>
                            <option value="2">商业银行</option>
                            <option value="3">邮政银行</option>
                            <option value="4">建设银行</option>-->
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-col-md4 layui-col-md-offset4">
                    <button class="layui-btn layui-bg-blue"  id="okk" lay-submit lay-filter="okkFilter" >确认</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

<!--打印弹出层-->
<div id="main" style="display: none">
    <form class="layui-form" lay-filter="test" >
        <div style="width: 600px;" id="day">
            <div style="margin-left: 50px">
                <h1 style="margin-bottom: 20px;margin-top: 20px"><span style="font-size: 24px;font-family: 宋体;font-weight: bold">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp划款指令</span></h1>
                <span style="font-size: 13px;font-family: 宋体;margin-bottom: 5px;">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp年&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp月&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp日</span>
                <table border="1px" style="border-collapse: collapse;width: 90%;height: 90%;font-size: 10px;font-family: 宋体;margin-bottom: 10px">
                    <tr style="height: 30px">
                        <td>付款户名称：<span id="accName"></span></td>
                        <td>收款户名称：</td>
                    </tr>
                    <tr style="height: 30px">
                        <td>付款账号：<span id="accNumber"></span></td>
                        <td>收款账号：</td>
                    </tr>
                    <tr style="height: 30px">
                        <td>开户行：<span id="startAddress"></span></td>
                        <td>开户行：</td>
                    </tr>
                    <tr style="height: 30px">
                        <td>大写金额：<span id="maxMoney"></span></td>
                        <td>小写金额：<span id="minMoney"></span></td>
                    </tr>
                    <tr style="height: 30px">
                        <td>支付日期：</td>
                        <td></td>
                    </tr>
                    <tr style="height: 55px">
                        <td colspan="2">划款事由及备注：<span id="type"></span></td>
                    </tr>
                    <tr style="height: 90px">
                        <td colspan="2">划款指印鉴定</td>
                    </tr>
                    <tr style="height: 35px">
                        <td colspan="2">管理人：&nbsp&nbsp&nbsp&nbsp经办人：&nbsp&nbsp&nbsp&nbsp复核人：&nbsp&nbsp&nbsp&nbsp审批人：&nbsp&nbsp&nbsp&nbsp</td>
                    </tr>
                    <tr style="height: 35px">
                        <td colspan="2">管理人：&nbsp&nbsp&nbsp&nbsp经办人：&nbsp&nbsp&nbsp&nbsp复核人：&nbsp&nbsp&nbsp&nbsp审批人：&nbsp&nbsp&nbsp&nbsp</td>
                    </tr>
                </table>
                <span style="margin-top: 20px;font-size: 10px;font-family: 宋体;">重要提示：</span><br/>
                <span style="font-size: 15px;font-family: 宋体;">1、指令审核无误后，托管人应按照指令条款与托管协议规定时间内划款。</span><br/>
                <span style="font-size: 15px;font-family: 宋体;">2、项目投资划款指令必须附有被投资对象签署的表明投资额和付款期望的书面付款通知，</span><br/>
                <span style="font-size: 15px;font-family: 宋体;">投资协议和托管协议规定的批准划款事项的书面决议文件。费用支出划款指令需附有费用</span><br/>
                <span style="font-size: 15px;font-family: 宋体;">明细、相关协议、合同、函件通知等相关证明文件和材料，收益分配划款须附有合伙人账</span><br/>
                <span style="font-size: 15px;font-family: 宋体;">户明细、经加盖合伙人企业公章的收益分配方案或《合伙协议》约定的相关文件。</span><br/>
                <span style="font-size: 15px;font-family: 宋体;">3、管理人保证划款指令内容符合《合伙协议》的规定。</span>
                <div id="btn" style="margin-left: 300px">
                    <div style="height: 50px"><a id="btn1" onclick="aa()" class="layui-btn layui-btn-sm" style="font-size: 15px;margin-left: 250px;margin-top: 5px;">打印</a></div>
                </div>
            </div>
        </div>
    </form>
</div>

<!--脚本代码-->
<script type="text/javascript">
    layui.use(['table','layer','form','laypage','util','jquery'],function () {
    //导入模块并得到模块对象
     var table = layui.table,//表格对象
     layer = layui.layer,//弹层对象
     form = layui.form,//表单对象
     laypage = layui.laypage,//分页组件
      $ = layui.jquery,//jquery对象
        util = layui.util;//工具对象
        var vals="";
          //渲染表格对象
        table.render({
        elem: "#demo",//表格对象
        url: "../Transfer/tran",//后台服务路径
        method: "GET",//提交方式
        height:740,
         toolbar: "#demoTableId",//表格上方普通工具栏
         //一页显示5条数据
         limit: 15
            ,cols: [[ //表头
                {checkbox:true},
                /*{field: 'tranId', title:'划款编号',align: 'center'},*/
                {field: 'caIds', title:'接收现金账号',align: 'center',templet:function (d) {
                        for (var i = 0; i <vals.length ; i++) {
                            if (vals[i].caId==d.caId){
                                return vals[i].accName;
                            }
                        }
                    }},
                {field: 'money', title:'划款金额(元)',align: 'center'},
                {field: 'tranDate', title:'划款日期',align: 'center'},
                {field: 'arrival', title:'到账日期',align: 'center'},
                {field: 'purpose', title:'用途',align: 'center'},
                {field: "caId", title: '划款账户', align: "center",templet:function (d) {
                        for (var i = 0; i <vals.length ; i++) {
                            if (vals[i].caId==d.caId){
                                return vals[i].accName;
                            }
                        }
                    }},
                {fixed: 'right', title:'操作', toolbar: '#barDemo',align:'center',width: 300}
            ]],
            limits: [5, 10,20,30,50],
            page:true,
            parseData: function(data){ //将原始数据解析成 table 组件所规定的数据
                //$("#stockId").remove();
                vals=data.cashAccountT;
                var htmlVal="<option value=''>---请选择---</option>";
                //动态生成下拉框
                for (var i=0;i<vals.length;i++){
                    htmlVal+="<option value='"+vals[i].caId+"'>"+vals[i].accName+"</option>";
                }
                $("#caId").append(htmlVal);
                $("#caIds").append(htmlVal);
                return {
                    "code": data.code, //解析接口状态
                    "msg": data.msg, //解析提示文本
                    "count": data.count, //解析数据长度
                    "data": data.data //解析数据列表
                }}
        });
        //监听添加/修改页的提交操作[该表单的提交操作] [保存按钮]
        //定义页面操作方式
        var method=" ";
        form.on('submit(okkFilter)', function(data){
            //将表单中各字段值转换为json字符串
            var json=JSON.stringify(data.field);
            //ajax提交数据
            //使用ajax删除选中的
            $.ajax({
                type: method,//提交方式
                url: "../Transfer/Transfer",//后台Servlet路径
                data:JSON.stringify(data.field) ,
                dataType:"text",
                contentType:"application/json;charset=utf-8",
                //提交成功后回调操作
                success: function(msg){
                    layer.closeAll();//关闭对话框
                    layer.msg(msg);//弹出提示框
                    //重新加载表格数据
                    table.reload('demo', {
                        data: data
                    });
                }
            });
            return false;
        });

        //表格头部工具栏事件代码，根据lay-event属性值判断执行相应的代码
        table.on('toolbar(test)', function(obj) {
            //检查表格选择操作状态
            var checkStatus = table.checkStatus(obj.config.id);
            //判断事件event值
            switch(obj.event) {
                //批量删除操作：删除选定的多行数据
                case "batchDel":
                    //获得选中的表格行
                    var data = checkStatus.data;
                    //判断是否大于0行
                    if(data.length>0){
                        layer.confirm('请确认是否真的删除?', function(index){
                            //获取所有选择的id
                            var tranIdStr="";

                            for (var i = 0; i < data.length; i++) {
                                tranIdStr = tranIdStr+data[i].tranId+",";//累加字符
                            }
                            //去掉最后多余逗号
                            tranIdStr=tranIdStr.substring(0,tranIdStr.length-1);
                            layer.close(index);
                            //使用ajax删除选中的
                            $.ajax({
                                type: "put",//提交方式为put,替代delte请求
                                url: "../Transfer/batchDel?tranIdStr="+tranIdStr,//后台Servlet路径
                                success: function(msg){
                                    layer.msg('删除成功');
                                    //重新加载表格数据
                                    table.reload('demo', {
                                        data: data
                                    });
                                }
                            });
                        });
                    }else{
                        //没有选择数据行
                        layer.msg('你至少选一行！');
                    }
                    break;
                case 'add':
                    //设置请求方式为post,表示增加
                    method="post";
                    //清空表单
                    $("#mainForm")[0].reset();
                    layer.open({
                        type: 1,//外部页面为2，内部层1
                        title: '<span style=\'color:#ffffff\' ><i class=\'layui-icon\'>&#xe6b2;</i> 添加划款指令</span>',
                        area: ['60%', '40%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-lan',
                        anim:1,
                        content:$("#MaxDiv").html(),
                        success: function(msg) {
                            //重新加载表格数据
                            table.reload('demo', {
                                data: data
                            });
                        }
                    });
                    //将主键设置成允许修改[防止因先修改，后增加时，该字段被设置为只读]
                    $("input[name='tranId']").prop("readonly",false);
                    break;
            }
        });

        //监听表格行工具(操作)事件
        table.on("tool(test)",function (obj) {
            //得到表格行数据
            var data=obj.data;
            //判断事件event值，与lay-event属性比较
            //判断是否为行修改操作
            if (obj.event=="update"){
                //将设置表单操作方式为修改
                method="put";
                //设置界面信息
                layer.open({
                    type: 1,
                    title:'<span style=\'color:white\'><i class=\'layui-icon\'>&#xe6b2;</i> 修改划款指令</span>',
                    area: ['60%', '40%'],
                    /*offset:"10px",//设置坐标*/
                    shade: 0.4,
                    skin: 'layui-layer-lan',
                    anim:1,
                    content: $("#MaxDiv").html()
                });
                //将当前行数据显示在表单各字段中
                form.val("myForm", {
                    "tranId": data.tranId,
                    "caIds": data.caIds,
                    "money":data.money,
                    "tranDate":data.tranDate,
                    "arrival":data.arrival,
                    "purpose":data.purpose,
                    "caId":data.caId
                });
            }else if (obj.event=="delete"){//判断为删除
                layer.confirm("您要删除划款指令编号为"+data.tranId+"这行数据?",function (index) {
                    layer.close(index);
                    $.ajax({
                        type: "delete",
                        url: "../Transfer/tran/"+data.tranId,//后台路径
                        success: function(msg){
                            //重新加载表格数据
                            table.reload('demo', {
                                data: data
                            });
                        }
                    });
                });
            }else if (obj.event=="dayin"){

                $.ajax({
                    url:"../Transfer/method/selectById/"+data.tranId+"/"+data.caId,
                    type:"put",
                    cyan:false,
                    success:function (data) {
                        if (data=="休假日不可以进行增加、删除、修改操作"){
                            layer.msg(data);
                            return false;
                        }

                        var load=layer.open({
                            type: 1,//外部页面为2，内部层1
                            title: '<span style=\'color:#ffffff\' ><i class=\'layui-icon\'>&#xe6b2;</i>打印划款指令</span>',
                            area: ['50%', '100%'],
                            fix: false,
                            maxmin: true,
                            /*offset:"10px",//设置坐标*/
                            shadeClose: true,
                            shade: 0.4,
                            skin: 'layui-layer-lan',
                            anim:1,
                            content:$("#day").html(),
                            success: function(msg) {
                                //重新加载表格数据
                                table.reload('demo', {
                                    data: data
                                });
                            }
                        });

                        var ti=data.ti;
                        var ac=data.ac;
                        //付款户名称
                        $("#accName").html(ac.accName);
                        //付款账户
                        $("#accNumber").html(ac.bankCard);
                        //开户行
                        $("#startAddress").html(ac.bankName);
                        //大写金额
                        $("#maxMoney").html(capital(ti.money));
                        //小写金额
                        $("#minMoney").html(ti.money);
                        //划款事由
                        $("#type").html(ti.purpose);

                        layer.open({
                            type: 1,//外部页面为2，内部层1
                            title: '<span style=\'color:#ffffff\' ><i class=\'layui-icon\'>&#xe6b2;</i>打印划款指令</span>',
                            area: ['50%', '100%'],
                            fix: false,
                            maxmin: true,
                            /*offset:"10px",//设置坐标*/
                            shadeClose: true,
                            shade: 0.4,
                            skin: 'layui-layer-lan',
                            anim:1,
                            content:$("#day").html(),
                            success: function(msg) {
                                //重新加载表格数据
                                table.reload('demo', {
                                    data: data
                                });
                            }
                        });
                        layer.close(load);
                    }
                });
            }
        });

        function capital(moneys){
            var money = moneys;
            var fraction = ['角','分'];
            var digit = ['零','壹','贰','叁','肆','伍','陆','柒','捌','玖'];
            var unit = [['元','万','亿'],['','拾','佰','仟']];
            var head = money < 0?'欠':'';
            money = Math.abs(money);
            var s = '';
            for (var i = 0; i < fraction.length; i++) {
                s += (digit[Math.floor(money * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
            }
            s = s || '整';
            money = Math.floor(money);
            for (var i = 0; i < unit[0].length && money > 0; i++) {
                var p = '';
                for (var j = 0; j < unit[1].length && money > 0; j++) {
                    p = digit[money % 10] + unit[1][j] + p;
                    money = Math.floor(money / 10);
                }
                s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
            }
            var sum= head + s.replace(/(零.)*零元/,'元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
            return sum;
        }

        //多条件搜索
        //搜索表单中提交按钮的事件代码
        form.on("submit(provinceSearch)",function (data) {
            //定义表单数据对象
            var formData=data.field;
            //得到表单数据json字符串
            var json=JSON.stringify(data.field);
            //重新加载表格对象
            table.reload("demo",{
                //页码
                page:{
                    curr:1
                },
                //条件数据，会带到后台
                where:{
                    tranDate:formData.tranDate,
                    arrival:formData.arrival
                }
            });
            return false;
        });
    });
</script>
</blockquote>
</body>
</html>